﻿using Abp.Domain.Entities.Auditing;
using FutureApp.Users;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Abp.MultiTenancy;

namespace FutureApp.Authorization.Permissions
{
    /// <summary>
    /// 权限规则
    /// </summary>
    [Table("PermissionDefinitions")]
    public class PermissionDefinition : FullAuditedEntity<Guid, User>
    {
        /// <summary>
        /// <see cref="Code"/> 的最大长度
        /// </summary>
        public const int MaxCodeLength = 50;
        /// <summary>
        /// <see cref="Name"/> 的最大长度
        /// </summary>
        public const int MaxNameLength = 256;
        /// <summary>
        /// <see cref="Summary"/> 的最大长度
        /// </summary>
        public const int MaxSummaryLength = 512;
        
        /// <summary>
        /// 权限规则
        /// </summary>
        [Required]
        [StringLength(MaxCodeLength)]
        public virtual string Code { get; set; }

        /// <summary>
        /// 权限名称
        /// </summary>
        [Required]
        [StringLength(MaxNameLength)]
        public virtual string Name { get; set; }

        /// <summary>
        /// 权限概述
        /// </summary>
        [StringLength(MaxSummaryLength)]
        public virtual string Summary { get; set; }
        
        /// <summary>
        /// 多租户设置
        /// </summary>
        public virtual MultiTenancySides MultiTenancySides { get; set; }

        /// <summary>
        /// 父权限定义Id
        /// </summary>
        public virtual Guid? ParentId { get; set; }

        /// <summary>
        /// 父权限
        /// </summary>
        [ForeignKey(nameof(ParentId))]
        public virtual PermissionDefinition Parent { get; set; }

        /// <summary>
        /// 子权限
        /// </summary>
        [ForeignKey(nameof(ParentId))]
        public virtual ICollection<PermissionDefinition> Children { get; set; }
    }
}
